package com.example.demo.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.base.config.auth.UserInfoShareHolder;
import com.example.demo.base.login.dto.UserCache;
import com.example.demo.domain.PageResult;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.exam.QueryModel;
import com.example.demo.domain.exam.condition.ExamClassStaffCondition;
import com.example.demo.dto.ExamClassStaffDTO;
import com.example.demo.dto.ResponseDto;
import com.example.demo.dto.UserListDto;
import com.example.demo.param.UserParam;
import com.example.demo.param.UserRoleParam;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * TODO
 *
 * @author mazh47622
 * @date2024/2/20
 * @modify -----------------------------------------------------------------------------------------------------
 * |修改单号|修改人员|修改日期|评审人员|修改说明
 * -----------------------------------------------------------------------------------------------------
 * |      |       |      |       |
 * -----------------------------------------------------------------------------------------------------
 */
@Controller
@RequestMapping("/user/userInfo")
public class UserInfoController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户信息
     * @param param
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public ResponseDto<Page<User>> list(@RequestBody UserParam param) {
        System.out.println("heheeheheh");
        Page list = userService.list(param);
        ResponseDto responseDto = new ResponseDto<>().buildSucceedHasData(list);
        return responseDto;
    }


    /**
     * 查询用户信息,联表
     * @param model
     * @return
     */
    @RequestMapping("/listPage")
    @ResponseBody
    public PageResult<UserListDto> listPage(@RequestBody QueryModel<UserParam> model) {
        return userService.listPage(model);
    }

    /**
     * 实名认证
     * @param param
     * @return
     */
    @RequestMapping("/identity/verification")
    @ResponseBody
    public boolean identity(@RequestBody UserParam param) {
        UserCache userInfo = UserInfoShareHolder.getUserInfo();
        param.setId(userInfo.getUser().getId());
        userService.identity(param);
        return true;
    }


    /**
     * 修改用户角色
     * @param param
     * @return
     */
    @RequestMapping("/updateUserInfoOfRole")
    @ResponseBody
    public boolean updateUserInfoOfRole(@RequestBody UserParam param){
        userService.updateUserInfoOfRole(param);
        return true;
    }

    /**
     * 用户状态修改
     * @param param
     * @return
     */
    @RequestMapping("/modifyUserStatus")
    @ResponseBody
    public ResponseDto modifyUserStatus(@RequestBody UserParam param){
        userService.modifyUserStatus(param);
        return new ResponseDto<>().buildSucceedHasData(true);
    }

}
